﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_DeliveryPlanController : BaseApiController
    {
        #region DI

        public PB_DeliveryPlanController(IPB_DeliveryPlanBusiness pB_DeliveryPlanBus)
        {
            _pB_DeliveryPlanBus = pB_DeliveryPlanBus;
        }

        IPB_DeliveryPlanBusiness _pB_DeliveryPlanBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_DeliveryPlan>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_DeliveryPlanBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<PB_DeliveryPlan> GetTheData(IdInputDTO input)
        {
            return await _pB_DeliveryPlanBus.GetTheDataAsync(input.id);
        }       

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_DeliveryPlan data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_DeliveryPlanBus.AddDataAsync(data);
            }
            else
            {
                await _pB_DeliveryPlanBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_DeliveryPlanBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 保存发货计划及明细信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddDataList(SavaDataDeliveryPlan data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                await _pB_DeliveryPlanBus.AddDataList(data);
            }
            else
            {
                await _pB_DeliveryPlanBus.UpdateDataList(data);
            }
        }

        /// <summary>
        /// pc 查看发货计划
        /// </summary>
        /// <param name="ParentId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<DeliveryPlanListInfo> GetDeliveryPlanListInfo(string ParentId)
        {
            var data = await _pB_DeliveryPlanBus.GetDeliveryPlanListInfo(ParentId);
            return data;
        }

        /// <summary>
        /// 审核发货计划
        /// </summary>
        /// <param name="Id">发货计划id</param>
        /// <returns></returns>
        [HttpPost]
        public async Task ToExamineOk(string Id)
        {
            await _pB_DeliveryPlanBus.ToExamineOk(Id);
        }

        /// <summary>
        /// 获取发货计划列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<PB_DeliveryPlanList>> GetDataListInfo(PageInput<PB_ScheduleDetailConditionDTO> input)
        {
            var list = await _pB_DeliveryPlanBus.GetDataListInfo(input);
            return list;
        }
        /// <summary>
        /// 获取当前操作人的工厂 amin所有工厂
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Base_Department>> GetDetpList()
        {
            return await _pB_DeliveryPlanBus.GetDetpListAsync();
        }
        /// <summary>
        /// 大屏发货进度（重量比例）
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天。默认为0</param>
        /// <returns>{"label": "发货进度","value": 43.2,"data": 100}</returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanProgressDTO GetTodayProgress(int Days = 0)
        {
            return _pB_DeliveryPlanBus.GetTodayProgressAsync(Days);
        }
        /// <summary>
        /// 大屏显示当日待发货项目数量
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天。默认为0</param>
        /// <returns>{"value": "100"}</returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanValueDTO GetTodayReadyDeliveryProject(int Days=0)
        {
            return _pB_DeliveryPlanBus.GetTodayReadyDeliveryProject(Days);
        }
        /// <summary>
        /// 大屏显示当日已备货数量
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天。默认为0</param>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanValue3DTO GetTodayPickUpAmount(int Days = 0)
        {
            return _pB_DeliveryPlanBus.GetTodayPickUpAmount(Days);
        }
        /// <summary>
        /// 大屏显示当日未备货数量
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天。默认为0</param>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanValue3DTO GetTodayNoPickUpAmount(int Days = 0)
        {
            return _pB_DeliveryPlanBus.GetTodayNoPickUpAmount(Days);
        }
        /// <summary>
        /// 大屏显示当日已发货数量
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天。默认为0</param>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanValue3DTO GetTodayDeliveryAmount(int Days=0)
        {
            return _pB_DeliveryPlanBus.GetTodayDeliveryAmount(Days);
        }
        /// <summary>
        /// 大屏显示累计发货重量
        /// </summary>
        /// <returns>{value": 43.12}</returns>
        [HttpPost]
        [NoCheckJWT]
        public PB_DeliveryPlanProgressDTO GetTodayTotalWeight(int Days = 0)
        {
            return _pB_DeliveryPlanBus.GetTodayTotalWeightAsync(Days);
        }
        /// <summary>
        /// 大屏显示计划列表
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        //[NoCheckJWT]
        //public async Task<List<PB_DeliveryPlanDetails2DTO>> GetDeliveryPlanList()
        //{
        //    return await _pB_DeliveryPlanBus.GetDeliveryPlanList();
        //}
        /// <summary>
        /// 大屏显示计划列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public async Task<List<PB_DeliveryPlanDetails2DTO>> GetDeliveryPlanList2()
        {
            return await _pB_DeliveryPlanBus.GetDeliveryPlanList2();
        }
        /// <summary>
        /// 大屏显示发货超时
        /// </summary>
        /// <param name="Days">到今天的天数。-1表示昨天</param>
        /// <returns>超时项目列表</returns>
        [HttpPost]
        [NoCheckJWT]
        public Task<List<PB_DeliveryPlanDelayNameValueDTO>> GetDeliveryPlanDelayList(int Days=0)
        {
            return _pB_DeliveryPlanBus.GetDeliveryPlanDelayList(Days);
        }
        /// <summary>
        /// 大屏显示7日发货城市
        /// </summary>
        /// <param name="Days">到今天的天数。默认为0</param>
        /// <returns>[['新乡市',[[{name: '新乡市'}, {name: '新乡市', value: 200, shippingInfo: 发货总数:2000件 }], [{name: '新乡市'}, {name: '呼和浩特市', value: 100, shippingInfo: 发货数:1000件 }], [{name: '新乡市'}, {name: '成都市', value: 100, shippingInfo: 发货数:1000件 }]]]]</returns>
        [HttpPost]
        [NoCheckJWT]
        public async Task<List<List<object>>> GetDeliveryPlanCity(int Days=0)
        {
            return await _pB_DeliveryPlanBus.GetDeliveryPlanCity(Days);
        }
        #endregion
    }
}